//
//  WPReadingIndivalCaseCell.m
//  wobingwoyi
//
//  Created by WGP on 16/8/23.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPReadingIndivalCaseCell.h"
#import "WPReadingCellBtn.h"
#import "UIImage+AsyncDraw.h"

#define NAME_FONT 16
#define INFO_FONT 14

@interface WPReadingIndivalCaseCell ()

@property(nonatomic,strong)UIImageView *iconView;
@property(nonatomic,strong)UILabel *nameLabel;
@property(nonatomic,strong)UIImageView *uploadImageView;
@property(nonatomic,strong)UILabel *uploadTimeLabel;
@property(nonatomic,strong)UILabel *diseaseLabel;
@property(nonatomic,strong)UILabel *hospitalLabel;
@property(nonatomic,strong)UILabel *doctorLabel;
@property(nonatomic,strong)UIView *lineView;
@property(nonatomic,strong)WPReadingCellBtn *eyeBtn;
@property(nonatomic,strong)WPReadingCellBtn *likeBtn;
@property(nonatomic,strong)WPReadingCellBtn *commitBtn;

@end
@implementation WPReadingIndivalCaseCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = GlobalBgColor;
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setupUI];
    }
    return self;
}

-(void)setupUI
{
    [self myContentView];
    [self iconView];
    [self nameLabel];
    [self uploadTimeLabel];
    [self uploadImageView];
    [self diseaseLabel];
    [self doctorLabel];
    [self hospitalLabel];
    [self lineView];
    [self eyeBtn];
    [self likeBtn];
    [self commitBtn];
}

//模型赋值
-(void)setModel:(WPMRModel *)model
{
    _model = model;
    
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:model.userImage] placeholderImage:[UIImage imageNamed:@"touxiang3"]completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
    }];
    self.nameLabel.text = model.userName;
    self.uploadTimeLabel.text = [[WPDateFormatterManager sharedManager] timeStrWithTimeStampStr:[NSString stringWithFormat:@"%zd",model.uploadTime] formatStr:@"yyyy.MM.dd"];
    self.diseaseLabel.text = [NSString stringWithFormat:@"疾病名称:  %@",model.name];
    self.doctorLabel.text = [NSString stringWithFormat:@"诊断医生:  %@",model.doctor];
    self.hospitalLabel.text = [NSString stringWithFormat:@"诊断医院:  %@",model.hospital];
    [self.eyeBtn setTitle:[NSString stringWithFormat:@"%zd",model.readAmount] forState:UIControlStateNormal];
    
    [self.likeBtn setTitle:[NSString stringWithFormat:@"%zd",model.collectAmount] forState:UIControlStateNormal];
    [self.commitBtn setTitle:[NSString stringWithFormat:@"%zd",model.appraiseAmount] forState:UIControlStateNormal];
}

-(UIView *)myContentView
{
    if (_myContentView == nil)
    {
        _myContentView = [UIView new];
        _myContentView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_myContentView];
        
        [_myContentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.contentView);
            make.top.equalTo(self.contentView).offset(5);
            make.bottom.equalTo(self.contentView).offset(-5);
        }];
        
    }
    return _myContentView;
}

-(UIImageView *)iconView
{
    if (_iconView == nil)
    {
        _iconView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"touxiang3"]];
        [_iconView sizeToFit];
        
        _iconView.layer.cornerRadius = 15;
        _iconView.layer.masksToBounds = YES;
        
        [self.myContentView addSubview:_iconView];
        
        [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(self.myContentView).offset(10);
            make.width.height.mas_equalTo(35);
        }];
    }
    return _iconView;
}

-(UILabel *)nameLabel
{
    if (_nameLabel == nil)
    {
        _nameLabel = [UILabel new];
        _nameLabel.text = @"昵称";
        _nameLabel.font = [UIFont systemFontOfSize:NAME_FONT];
//        _nameLabel.textColor = RGB_SAME(51);
        [_nameLabel sizeToFit];
        [self.myContentView addSubview:_nameLabel];
        
        [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.iconView.mas_right).offset(10);
            make.centerY.equalTo(self.iconView);
        }];
    }
    return _nameLabel;
}

-(UILabel *)uploadTimeLabel
{
    if (_uploadTimeLabel == nil)
    {
        _uploadTimeLabel = [UILabel new];
        _uploadTimeLabel.font = [UIFont systemFontOfSize:INFO_FONT];
        _uploadTimeLabel.textColor = GLobalFontColor;
        [_uploadTimeLabel sizeToFit];
        [self.myContentView addSubview:_uploadTimeLabel];
        
        [_uploadTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.myContentView).offset(-10);
            make.centerY.equalTo(self.iconView);
        }];
    }
    return _uploadTimeLabel;
}

-(UIImageView *)uploadImageView
{
    if (_uploadImageView == nil)
    {
        _uploadImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"shangchuan"]];
        [_uploadImageView sizeToFit];
        [self.myContentView addSubview:_uploadImageView];
        
        [_uploadImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.uploadTimeLabel.mas_left).offset(-5);
            make.centerY.equalTo(self.iconView);
        }];
    }
    return _uploadImageView;
}

-(UILabel *)diseaseLabel
{
    if (_diseaseLabel == nil)
    {
        _diseaseLabel = [UILabel new];
        _diseaseLabel.text = [NSString stringWithFormat:@"疾病名称: %@",@""];
        _diseaseLabel.font = [UIFont systemFontOfSize:INFO_FONT];
        _diseaseLabel.textColor = RGB_SAME(51);
        [_diseaseLabel sizeToFit];
        [self.myContentView addSubview:_diseaseLabel];
        
        [_diseaseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.iconView);
            make.top.equalTo(self.iconView.mas_bottom).offset(10);
        }];
    }
    return _diseaseLabel;
}

-(UILabel *)doctorLabel
{
    if (_doctorLabel == nil)
    {
        _doctorLabel = [UILabel new];
        _doctorLabel.text = [NSString stringWithFormat:@"诊断医生: %@",@""];
        _doctorLabel.font = [UIFont systemFontOfSize:INFO_FONT];
        _doctorLabel.textColor = RGB_SAME(51);
        [_doctorLabel sizeToFit];
        [self.myContentView addSubview:_doctorLabel];
        
        [_doctorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.diseaseLabel);
            make.top.equalTo(self.diseaseLabel.mas_bottom).offset(10);
        }];
    }
    return _doctorLabel;
}

-(UILabel *)hospitalLabel
{
    if (_hospitalLabel == nil)
    {
        _hospitalLabel = [UILabel new];
        _hospitalLabel.text = [NSString stringWithFormat:@"诊断医院: %@",@""];
        _hospitalLabel.font = [UIFont systemFontOfSize:INFO_FONT];
        _hospitalLabel.textColor = RGB_SAME(51);
        [_hospitalLabel sizeToFit];
        [self.myContentView addSubview:_hospitalLabel];
        
        [_hospitalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.doctorLabel);
            make.top.equalTo(self.doctorLabel.mas_bottom).offset(10);
        }];
    }
    return _hospitalLabel;
}

-(UIView *)lineView
{
    if (_lineView == nil)
    {
        _lineView = [UIView new];
        _lineView.backgroundColor = GLobalLineColor;
        [self.myContentView addSubview:_lineView];
        
        [_lineView  mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.hospitalLabel);
            make.right.equalTo(self.myContentView);
            make.height.mas_equalTo(0.5);
            make.top.equalTo(self.hospitalLabel.mas_bottom).offset(10);
        }];
    }
    return _lineView;
}

-(WPReadingCellBtn *)eyeBtn
{
    if (_eyeBtn == nil)
    {
        _eyeBtn = [WPReadingCellBtn buttonWithType:UIButtonTypeCustom];
        
        [_eyeBtn setImage:[UIImage imageNamed:@"kanguo"] forState:UIControlStateNormal];
         [_eyeBtn setTitle:@"0" forState:UIControlStateNormal];
        [_eyeBtn setTitleColor:GLobalFontColor forState:UIControlStateNormal];
        _eyeBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [_eyeBtn.titleLabel sizeToFit];
        [self.myContentView addSubview:_eyeBtn];
        
        [_eyeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.lineView);
            make.top.equalTo(self.lineView.mas_bottom).offset(4);
            make.width.mas_equalTo(80);
        }];
        
    }
    return _eyeBtn;
}

-(WPReadingCellBtn *)likeBtn
{
    if (_likeBtn == nil)
    {
        _likeBtn = [WPReadingCellBtn buttonWithType:UIButtonTypeCustom];
    
        [_likeBtn setImage:[UIImage imageNamed:@"shoucang"] forState:UIControlStateNormal];
        [_likeBtn setTitle:@"0" forState:UIControlStateNormal];
        [_likeBtn setTitleColor:GLobalFontColor forState:UIControlStateNormal];
        _likeBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [self.myContentView addSubview:_likeBtn];
        
        [_likeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.eyeBtn);
            make.left.equalTo(self.eyeBtn).offset(80);
            make.width.mas_equalTo(80);
            
        }];
    }
    return _likeBtn;
}

-(WPReadingCellBtn *)commitBtn
{
    if (_commitBtn == nil)
    {
          _commitBtn = [WPReadingCellBtn buttonWithType:UIButtonTypeCustom];
          [_commitBtn setImage:[UIImage imageNamed:@"pinglun"] forState:UIControlStateNormal];
          [_commitBtn setTitle:@"0" forState:UIControlStateNormal];
        [_commitBtn setTitleColor:GLobalFontColor forState:UIControlStateNormal];
        _commitBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [self.myContentView addSubview:_commitBtn];
        
        [_commitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.eyeBtn).offset(160);
            make.centerY.equalTo(self.eyeBtn);
            make.width.mas_equalTo(80);
        }];
    }
    return _commitBtn;
}


@end
